package com.aya.rabbitmq.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

/**
 * 自动确认队列
 */
@Service
public class AutoConfirmListener implements MessageListener {
    Logger logger = LoggerFactory.getLogger(AutoConfirmListener.class);
    @Override
    public void onMessage(Message message) {
        try {
            String messageBody = new String(message.getBody(), "UTF-8");
            Thread.sleep(2000);
            logger.info("队列监听器TextListener获得的内容:{}",messageBody);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
